package xyz.hzxiao.utils;

/**
 * 字符串脱敏
 *
 * @author ：FuXx
 * @className : xyz.hzxiao.utils.DesensitizationUtils
 * @since ：2023-08-22
 */
public class DesensitizationUtils {

    public static String replace(String source, String mask, int prefix, int suffix) {
        if (source == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0, n = source.length(); i < n; i++) {
            if (i < prefix) {
                sb.append(source.charAt(i));
                continue;
            }
            if (i > (n - suffix - 1)) {
                sb.append(source.charAt(i));
                continue;
            }
            sb.append(mask);
        }
        return sb.toString();
    }

}
